<template>
  <div>
    <!-- 项目负责人 -->
    <div class="main_content">
      <el-form id="s_form" :model="searchForm" :inline="true" ref="searchForm">
        <el-form-item prop="searchText">
          <el-input
            style="width:200px;" size='medium'
            clearable
            v-model="searchForm.searchText"
            placeholder="请输入查询关键字"
            @keydown.enter.native="doSearch()"
          ></el-input>
          <el-button size='medium' type="primary" @click="doSearch()" class="added" style='margin-left:15px;'>
            <i class="el-icon-search"></i>
            搜索
          </el-button>
        </el-form-item>
        <el-form-item>
          <el-button size='medium' v-if="showBack && searchForm.searchText" @click="doReturn()">
            <i class="el-icon-back"></i>
            清空
          </el-button>
        </el-form-item>
      </el-form>
      <myTable
        style="margin-top:15px"
        auto='getAllList'
        son='mainTable'
        :height="Height-210"
        min-width='130'
        :myColumn=tableProp
        hide='checkbox'
        ahide='index,checkbox,mySplitPage,tooltip,background'
        slots='操作,158,right'
        select='console'
        hook:created=' myTable.tableData = tableData '
      >
        <template slot-scope='button'>
          <!-- <div class="fCol" style='apadding:10px;'> -->
          <el-button type="success" size="mini" @click="handleDetail(button.scope.$index, button.scope.row)"
                     astyle='margin: 3px 0;'>
            <i class="el-icon-view"></i>
            详 情
          </el-button>
          <el-button type="primary" size="mini" @click="handleEdit(button.scope.$index, button.scope.row)">
            <i class="el-icon-edit"></i>
            编 辑
          </el-button>
          <!-- </div> -->
          <!-- <el-button type="danger" size="mini"  @click="handleDelete(button.scope.$switch, button.scope.row)">
            <i class="el-icon-circle-close"></i>
            删 除
          </el-button> -->
          <!-- <el-button type="danger" size="mini" v-if="button.scope.row.projectState==0" @click="handleDelete(button.scope.$switch, button.scope.row)">
            <i class="el-icon-circle-close"></i>
            删 除
          </el-button>
          <el-button
            type="info"
            size="mini"
            v-if="button.scope.row.projectState!=0"
            :disabled="button.scope.row.projectState!=0"
            @click="handleDelete(button.scope.$switch, button.scope.row)">
            <i class="el-icon-circle-close"></i>
            删 除
          </el-button> -->
        </template>
      </myTable>
    </div>
    <!--删除-->
    <el-dialog v-dialogDrag ref="dialog_isDelete" title="提示" :visible.sync="isDelete" width="32%">
      <span>是否删除此项目！</span>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="doDelete()">确 定</el-button>
        <el-button @click="isDelete = false">取 消</el-button>
      </span>
    </el-dialog>
    <!--修改 :rules="Editrules" ref="theEdit"-->
    <el-dialog v-dialogDrag title="修改数据" :visible.sync="isEdit" width="70%" :close-on-click-modal=false>
      <el-form id="pro2_edit_form" :model="theEdit" label-width="200px">
        <!-- <el-form-item label="项目日期" prop="editDate">
          <el-date-picker
            v-model="theEdit.editDate"
            type="datetimerange"
            align="left"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :picker-options="pickerOptions"
            value-format="yyyy-MM-dd hh:mm:ss"
            style="width:99.8%"
          ></el-date-picker>
        </el-form-item><br> -->
        <el-form-item label="编号类型" class="el-form-edit">
          <!-- <el-select v-model="theEdit.projectState" disabled> -->
          <el-select v-model="theEdit.numberType" style="width:40%">
            <el-option
              label="正常编号"
              value="1"

            ></el-option>
            <el-option
              label="特殊编号"
              value="2"
            ></el-option>
          </el-select>


          <div v-if="theEdit.numberType==2" style="width:60%;margin-top: 20px">
            <el-select v-model="theEdit.one" @change="setMylist(theEdit.one)">
              <el-option
                v-for="(v,i) in HzXlList"
                :key="i"
                :disabled="v.active"
                :label="v.name"
                :value="v.code"
              ></el-option>
            </el-select>
            <el-select v-model="theEdit.two" @change="setMylist(theEdit.two)">
              <el-option
                v-for="(v,i) in HzXlList"
                :key="i"
                :disabled="v.active"
                :label="v.name"
                :value="v.code"
              ></el-option>
            </el-select>
            <el-select v-model="theEdit.three" @change="setMylist(theEdit.three)">
              <el-option
                v-for="(v,i) in HzXlList"
                :key="i"
                :disabled="v.active"
                :label="v.name"
                :value="v.code"
              ></el-option>
            </el-select>
            <el-select v-model="theEdit.four" @change="setMylist(theEdit.four)">
              <el-option
                v-for="(v,i) in HzXlList"
                :key="i"
                :disabled="v.active"
                :label="v.name"
                :value="v.code"
              ></el-option>
            </el-select>
            <el-select v-model="theEdit.five" @change="setMylist(theEdit.five)">
              <el-option
                v-for="(v,i) in HzXlList"
                :key="i"
                :disabled="v.active"
                :label="v.name"
                :value="v.code"
              ></el-option>
            </el-select>
            <el-select v-model="theEdit.six" @change="setMylist(theEdit.six)">
              <el-option
                v-for="(v,i) in HzXlList"
                :key="i"
                :disabled="v.active"
                :label="v.name"
                :value="v.code"
              ></el-option>
            </el-select>
          </div>

        </el-form-item>


        <el-form-item label="状态" prop="projectState" class="el-form-edit">
          <!-- <el-select v-model="theEdit.projectState" disabled> -->
          <el-select v-model="theEdit.projectState" style="width:40%">
            <el-option
              v-for="item in status"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="项目编号" prop="projectNumber" class="el-form-edit">
          <el-input type="text" style="width:40%;" v-model="theEdit.projectNumber"></el-input>
        </el-form-item>
        <!--        <el-form-item label="项目编号" prop="projectNumber2" zref='z5'-->
        <!--                      z:e-input-0input='console.error(event,$this);$this.MCode[event.target.getAttribute("i")] = event.target.value = event.data;'>-->
        <!--          <span class="bold font15">YPES - </span>-->
        <!--          <el-input :value='MCode[1]' ref='input1' vmodel='MCode[1]' style='width:100px;' placeholder='项目名'-->
        <!--                    @input='console(arguments[0],1)'></el-input>-->
        <!--          <span class="bold font15" style="margin:0 3px;">-</span>-->
        <!--          <el-input :value='MCode[2]' ref='input2' vmodel='MCode[2]' style='width:100px;' placeholder='专业'-->
        <!--                    @input='console(arguments[0],2)'></el-input>-->
        <!--          <span class="bold font15" style="margin:0 3px;">-</span>-->
        <!--          <el-input :value='MCode[3]' ref='input3' vmodel='MCode[3]' style='width:100px;' placeholder='旁站'-->
        <!--                    @input='console(arguments[0],3)'></el-input>-->
        <!--          &lt;!&ndash; <span class="bold font15" style="margin:0 3px;">-</span> &ndash;&gt;-->
        <!--          &lt;!&ndash; <el-input style='width:100px;' placeholder='流水号' v-model='MCode[4]' disabled></el-input> &ndash;&gt;-->
        <!--          &lt;!&ndash; <el-input-->
        <!--            @input='inputCode'-->
        <!--            :value='theEdit.projectNumber2'-->
        <!--            vmodel="theEdit.projectNumber2"-->
        <!--            clearable-->
        <!--            @click.native="rules()"-->
        <!--            style="width:40%"-->
        <!--          ></el-input> &ndash;&gt;-->
        <!--        </el-form-item>-->
        <!--规则提示  -->
        <!-- <div v-show="isRules" style="padding-left:165px;">
          <span style="color:red">规则为（公司名-项目名-专业-旁站+流水号{缩写}）</span>
        </div> -->
        <!-- <el-form-item label="供应商" prop="supplierId">
          <el-select v-model="editSS" clearable multiple collapse-tags @change="theEdit.editSS=false" @visible-change='arguments[0]&&supplier()'>
            <div vif='editSS' ref=z1 style="line-height: 26px" class="tCenter cPointer font14" z-hover='opacity:0.9;color:#409EFF;' z:on-click=' $this.editSS = $this.editSS.length >= $this.optionsAll.length ? [] : $this.optionsAll.map(v=>v.value) '>
                {{ editSS.length >= optionsAll.length ? '取消全选' : '全选' }}
            </div>
            <el-option
              v-for="item in optionsAll"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
            <div class="page_div" style="padding-left:20px">
              <el-button type="primary" size="mini" @click="ziDingyi()">自定义</el-button>
              <div class="page_i" @click="rightI()" title="向下翻页">
                <i class="el-icon-arrow-down page_i_color" ></i>
              </div>
            </div>
          </el-select>
        </el-form-item> -->
        <el-form-item label="供应商" prop="supplier" class="el-form-edit el-form-edit2">
          <div v-for='(item,index) in Supplier' :key='index' style="margin-bottom:8px;">
            <el-input v-model="Supplier[index]" clearable style="width:40%"></el-input>
            <i v-if='index < Supplier.length - 1 || index > 0' class="el-icon-remove-outline Icon_margin icon_red"
               @click="Supplier.splice(index,1)"></i>
            <i v-else class="el-icon-circle-plus-outline Icon_margin icon_blue" @click="Supplier.push('')"></i>
            <i v-if='index > 0 && index>=Supplier.length - 1' class="el-icon-circle-plus-outline Icon_margin icon_blue"
               @click="Supplier.push('')"></i>
          </div>
          <!-- <div v-if="isSupp" style="margin:5px 0">
            <el-input v-model="Supplier[2]" clearable style="width:40%"></el-input>
            <i v-if="isPlus2" class="el-icon-circle-plus-outline Icon_margin" @click="addIcon2()"></i>
            <i v-if="isMinus2" class="el-icon-remove-outline Icon_margin" @click="minusIcon2()"></i>
          </div>
          <div v-if="isSupp3">
            <el-input v-model="Supplier[3]" clearable style="width:40%"></el-input>
            <i v-if="isPlus2" class="el-icon-plus" style="margin-left:5px;" @click="addIcon2()"></i>
            <i v-if="isMinus2" class="el-icon-minus" style="margin-left:5px;" @click="minusIcon2()"></i>
          </div> -->
        </el-form-item>
        <!-- <el-form-item v-if="isSupp" prop="supplier" class="el-form-edit el-form-edit2">
          <el-input v-model="theEdit.supplier" clearable style="width:40%"></el-input>
          <i v-if="isPlus2" class="el-icon-plus" style="margin-left:5px;" @click="addIcon2()"></i>
          <i v-if="isMinus2" class="el-icon-minus" style="margin-left:5px;" @click="minusIcon2()"></i>
        </el-form-item>
        <el-form-item v-if="isSupp3" prop="supplier" class="el-form-edit el-form-edit2">
          <el-input v-model="theEdit.supplier" clearable style="width:40%"></el-input>
        </el-form-item> -->

        <el-form-item label="业主" prop="HzuserYzIds" v-if="isYz" class="el-form-edit">
          <el-select v-model="theEdit.HzuserYzIds" multiple placeholder="请选择">
            <el-option
              v-for="item in Hzyzoptions"
              :key="item.userId"
              :label="item.userName"
              :value="item.userId">
            </el-option>
          </el-select>
        </el-form-item>


        <el-form-item label="人员分配" prop="totalUser" class="el-form-edit">
          <el-input v-model="theEdit.totalUser" clearable @click.native="showTable()" style="width:40%"></el-input>
        </el-form-item>
      </el-form>
      <!-- 人员分配 展开 -->
      <div v-if="isEditTable" class="flex">

        <div style="max-width:180px">
          <el-radio v-model="theAdd.radio" label="1" border style="width:90%">总监
            {{ theAdd.sel1.length ? `( ${theAdd.sel1.length} )` : '' }}
          </el-radio>
          <el-radio v-model="theAdd.radio" label="2" border style="width:90%">总代
            {{ theAdd.sel2.length ? `( ${theAdd.sel2.length} )` : '' }}
          </el-radio>
          <el-radio v-model="theAdd.radio" label="3" border style="width:90%">监理工程师
            {{ theAdd.sel3.length ? `( ${theAdd.sel3.length} )` : '' }}
          </el-radio>
          <el-radio v-model="theAdd.radio" label="4" border style="width:90%">监理员
            {{ theAdd.sel4.length ? `( ${theAdd.sel4.length} )` : '' }}
          </el-radio>
        </div>

        <div v-if="istableData2" class="showTableTwo" style="width: 100%">
          <el-row class="table_row">
            <el-form id="s_form" :model="searchForm2" :inline="true" ref="searchForm2">
              <el-form-item prop="searchText2">
                <el-input
                  size="mini"
                  style="width:200px;"
                  clearable
                  v-model="searchForm2.searchText2"
                  placeholder="请输入账号或姓名"
                  @keydown.enter.native="doSearch2()"
                ></el-input>
                <el-button type="primary" @click="doSearch2()" class="added" size="mini">
                  <i class="el-icon-search"></i>
                  搜索
                </el-button>
              </el-form-item>
              <el-form-item>
                <el-button v-if="showBack2" @click="doReturn2()" size="mini">
                  <i class="el-icon-back"></i>
                  返回
                </el-button>
              </el-form-item>
            </el-form>
            <!-- <el-button type="primary" size="mini" @click="doSure2()">确 认</el-button> -->
          </el-row>
          <el-row style="padding:0 10px 70px 10px;">
            <myTable
              :selectable="selectable"
              :dad-son='[$1,"addTable"]'
              auto='getShowUser'
              multiple
              style='margin-top:10px'
              min-width='130'
              :myColumn=tableProp2
              ahide='index,checkbox,mySplitPage,tooltip,background'
              slots='操作,165,right'
              @select='sel_AddTable'
              @resEnd='resEnd'
              hook:created=' myTable.tableData2 = tableData2 '
            >
            </myTable>
          </el-row>
        </div>

      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size='medium' icon='el-icon-success' type="primary" @click="doEdit()">确 定</el-button>
        <el-button size='medium' @click="docancel" style='margin-left:15px;'>取 消</el-button>
<!--        <el-button size='medium' @click="test" style='margin-left:15px;'>test</el-button>-->

      </span>
    </el-dialog>
  </div>
</template>
<script>
import {setTimeout} from 'timers';

const initCode = ['YPES', '', '', ''];
// const initCode2 = ['','',''];
const myCase = {
  __proto__: null,
  1: '总监',
  2: '总代',
  3: '监理工程师',
  4: '监理员'
};
export default {
  data() {
    return {

      Hzyzoptions:[],
      Hzyzvalue:"",
      isYz:false,
      HzXlList: [
        {name: "监理公司", code: "YPES", active: false},
        {name: "项目", code: "XM", active: false},
        {name: "主项号", code: "ZXH", active: false},
        {name: "专业", code: "ZY", active: false},
        {name: "文件类型代码", code: "WJLXDM", active: false},
        {name: "序列号", code: "XLH", active: false},
        {name: "无", code: "WU", active: false}],
      tempZongJian: [],
      loading: "",
      // reg: /^YPES\-EVA\-TJ\-PJ[0-9]{3}$/,
      // reg2: /^YPES\-EVA\-TJ\-PJ[0-9]{0,3}$/,
      reg: /^YPES$/,
      reg2: /^YPES$/,
      tableHeaderStyle: {
        //表头样式
        "background-color": "rgb(242,242,242)"
      },
      multipleSelection: [], //多选
      theRow: {}, //当前行数据
      theIndex: 0, //当前下标
      multiIDS: [], //多选
      addSS: [],
      editSS: [],
      MCode: initCode.concat(G.randomStr(3)),
      Supplier: [''],
      theAdd: {
        sel1: [],
        sel2: [],
        sel3: [],
        sel4: [],
        // supplierId: [],
      }, //新增数据
      isAdd: false, //是否新增
      isDelete: false, //是否删除
      hasMultiDelete: false, //是否多选
      searchForm: {
        searchText: "", //搜索字段
      },
      myTotal: 1, //分页总条数，默认1
      currentPage: 1, //初始化当前页
      nowPage: 1, //当前页
      thePageSize: 15, //每页条数
      tableData: [],
      tableProp: [

        {label: "项目所在地", prop: "area", sort: true},
        {label: "项目名称", prop: "projectName", sort: true},
        {label: "项目开始日期", prop: "createTime", sort: true, width: 180},
        {label: "项目管理员", prop: "projectLeaderName", sort: true},
        {label: "编号", prop: "projectNumber"},
        {label: "供应商", prop: "supplier", sort: true},
        {
          label: "状态", prop: "projectState", html(prop) {
            if (prop === 1) {
              return '<span style="color:red">正在进行</span>'
            } else if (prop === 2) {
              return '<span style="color:blue">已完成</span>'
            } else if (prop === 0)
              return '<span style="color:green">未开始</span>'
          }
        },
        {label: "创建人", prop: "createPerson"},
        // { label: "工程名称", prop: "programmeName" },
      ],
      //供应商
      optionsAll: [
        // { value: "ALL", label: "全选" }
      ],
      //状态
      status: [
        // { value: 0, label: "未开始" },
        {value: 1, label: "正在进行"},
        {value: 2, label: "已完成"},
      ],
      theEdit: {
        six: '',
        four: '',
        five: '',
        three: '',
        two: '',
        one: '',
        numberType: 1,
        editDate: [],
        HzuserYzIds:[],
        userYzIds:""
      },
      isEdit: false,
      searchForm2: {
        searchText2: "",
      },
      tableData2: [],
      istableData2: false,
      tableProp2: [
        {label: "姓名", prop: "userName", sort: true},
        {
          label: "专业", prop: "userMajorInfoList", sort: true, html(prop) {
            return Return(prop, (a, v) => a + '、' + v.majorName, '').slice(1);
          }
        },
        // { label: "专业", prop: "phoneNumber" },
        // { label: "账号", prop: "phoneNumber" },
        // { label: "角色", prop: "roleId", html(prop) {
        //   return prop === 1 ? '<span>系统管理员</span>' : '<span>项目管理员</span>';
        // } },
        {label: "岗位", sort: true, prop: "post"},
        // { label: "当前选择", sort: true, prop: "_current", width: 80 },
        // { label: "状态", prop: "userState", html(prop) {
        //   return prop === 1 ? '<span style=color:green>正常</span>' : '<span style=color:red>注销</span>';
        // } },
      ],
      oldOptions: [],//存储上一次数据
      //修改人员分配
      isEditTable: false,
      isEditTable2: false,
      tableProp3: [
        {label: "姓名", prop: "name"},
        {label: "角色", prop: "name", html: '吼吼'},
        {label: "权限", prop: "payCode", html: '请付钱!!'},
        {label: "状态", prop: "department", html: '呼呼'},
      ],
      tableData3: [],
      theDate: "", //日期范围
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            }
          }
        ]
      },
      isAddtwo: false,//项目管理员 新增
      isEdittwo: false,//项目管理员 修改
      restaurants: [],
      srcOrderNoArr: [],
      // rules:{
      //   projectState:[
      //     { required: true, message: "请输选择状态", trigger: "change" }
      //   ],
      //   projectNumber2:[
      //      { required: true, message: "项目编号规则为（公司名-项目名-专业-旁站+流水号{缩写}）", trigger: "blur" }
      //   ],
      //   supplier:[
      //     { required: true, message: "请输入供应商", trigger: "blur" }
      //   ],
      // },
      isRules: false,
      showBack: false,
      showBack2: false,
      // Editrules: {
      //   MCode: [
      //     {  required: true, message: "编号只能是数字或字母",trigger: "blur" }
      //   ]
      // },
      isMinus: false,//供应商 减号
      isPlus: true,//供应商 加号
      isSupp: false,//供应商 第二个
      user_name: '',
      agency: '',
      engineer: '',
      supervisor: '',
      symbol: '',
      symbol3: '',
      symbol4: '',

      consoleReg: /^[A-Za-z0-9]+$/i,
    };
  },
  components: {},
  watch: {
    'theAdd.radio'(val) {
      this.showChief(val);
    },
    // supplier:{
    //   handler: function() {
    //     this.csvS = [];//这是定义好的用于存放下拉提醒框中数据的数组
    //     var len = this.csvList.length;//csvList是页面初始化时得到的初始全部数据
    //     var arr = [];
    //     for (var i = 0; i < len; i++) {//根据输入框中inputName的值进行模糊匹配
    //       if (this.csvList[i].indexOf(this.inputName) >= 0) {
    //         arr.push(this.csvList[i]);//符合条件的值都放入arr中
    //       }
    //     }
    //     console.log(arr);

    //     //el-autocomplete元素要求数组内是对象，且有value属性，此处做一个格式调整
    //     for (var i = 0; i < arr.length; i++) {
    //       var obj = { value: "" };
    //       obj.value = arr[i];
    //       this.csvS.push(obj);
    //     }
    //   }
    // }
  },
  created() {
  this.HzgetYezhu()
    },
  methods: {
    test(){
      this.theEdit.HzuserYzIds=["070e4622-c9cc-4812-1aa4-07fbaw75e17b"]
    },
    // 获取全部业主
   async HzgetYezhu2(pid){
     this.isYz=false
     this.$nextTick(()=>{
       this.isYz=true
     })
     let list =[]
     this.theEdit.HzuserYzIds=[]

       let res =await $.post('http://yangzidaxingdiaozhuang.com/pxjy/system/proProject/getYzListByProId', {proId:pid})

         res.items.map((v,i)=>{
           list.push(v.userId)
         })
        this.theEdit.HzuserYzIds=list


    },

    // 获取全部业主
    async HzgetYezhu(){
    let res = await $.post('http://yangzidaxingdiaozhuang.com/pxjy/system/proProject/getYzList', {})
      this.Hzyzoptions=res.items
      console.log("--1--Hzyzoptions")
      console.log(this.Hzyzoptions)

    },

    setMylist() {

      this.HzXlList.map((v, i) => {
        if (v.code == this.theEdit.one) {
          v.active = true
        }else if (v.code == this.theEdit.two) {
          v.active = true
        }else if (v.code == this.theEdit.three) {
          v.active = true
        }else if (v.code == this.theEdit.four) {
          v.active = true
        }else if (v.code == this.theEdit.five) {
          v.active = true
        }else if (v.code == this.theEdit.six) {
          v.active = true
        }else {
          v.active=false
        }

      })
      console.log(this.HzXlList)
    },



    console(value, el) {
      !/^[A-Za-z0-9]+$/i.test(value) && (value = '');
      this.MCode[el] = this.$refs['input' + el].value = value;
      // console.warn( value, el, el.$el.firstElementChild, el.$el.firstElementChild.value );
    },
    //供应商加号
    addIcon() {
      this.isPlus = !this.isPlus;
      this.isMinus = !this.isMinus;
      this.isSupp = !this.isSupp;
    },
    //供应商减号
    minusIcon() {
      this.isPlus = !this.isPlus;
      this.isMinus = !this.isMinus;
      this.isSupp = !this.isSupp;
    },
    doReturn() {
      this.$refs.searchForm.resetFields()
      this.getAllList();
      this.showBack = false;
    },
    doReturn2() {
      this.$refs.searchForm2.resetFields()
      this.getShowUser();
      this.showBack2 = false;
    },
    //规则提示
    rules() {
      this.isRules = true;
    },
    ruleSupp() {
      this.isRules = false;
    },
    // querySearch(queryString, cb) {
    //   var csvS = this.csvS;
    //   cb(csvS);
    // },
    selectable(row, index) {
      return row._selectable !== false;
      /*if (row.userState == 2) {
          return false;
      } else {
          return true;
      }*/
    },
    //===============修改 人员分配 相关事件===========================
    //input点击事件  一级隐藏 显示
    showTable() {
      this.isEditTable = !this.isEditTable
    },
    //二级隐藏 显示
    editShowTableData() {
      this.isEditTable2 = !this.isEditTable2
    },
    //自定义跳转页面
    ziDingyi() {
      this.$router.push({name: "supplierManagement"});
    },
    //==============全选======================
    /*selectAll(val) {
      let allValues = [];
      for (let item of this.optionsAll) {
        allValues.push(item.value)
      };
      const oldVal = this.oldOptions.length === 1 ? this.oldOptions[0] : [];
      if (val.includes('ALL')) this.theAdd.supplier_id = allValues;
      if (oldVal.includes('ALL') && !val.includes('ALL')) this.theAdd.supplier_id = [];
      if (oldVal.includes('ALL') && val.includes('ALL')) {
        const switch = val.indexOf('ALL');
        val.splice(switch, 1);
        this.theAdd.supplier_id = val;
      };
      if (!oldVal.includes('ALL') && !val.includes('ALL')) {
        console.log(11)
        if (val.length === allValues.length - 1) this.theAdd.supplier_id = ['ALL'].concat(val);
      }
      this.oldOptions[0] = this.theAdd.supplier_id;
    },*/

    resEnd(son, tableData) {
      const A = this.theAdd; //['sel'+this.lastPositionType];
      // console.warn(this.lastPositionType,A);
      son.staticSel = true;
      const sel = A.radio * 1;
      // tableData.forEach(r=>r._current='');
      if (sel) {
        if (sel === 1 || sel === 4) {
          Loop(i => {
            const bool = i === sel;
            A['sel' + i].forEach(v => (v = v.userId) && (v = tableData.find(v2 => v2.userId === v)) && (v._selectable = bool));
          }, 1, 4, 1);
        } else {
          A.sel1.forEach(v => (v = v.userId) && (v = tableData.find(v2 => v2.userId === v)) && (v._selectable = false));
          A.sel4.forEach(v => (v = v.userId) && (v = tableData.find(v2 => v2.userId === v)) && (v._selectable = false));
          // const C = myCase[sel];
          Loop(i => {
            A['sel' + i].forEach(v => (v = v.userId) && (v = tableData.find(v2 => v2.userId === v)) && (v._selectable = true));
          }, 2, 3, 1);
        }
        ;
      }
      ;
      son.$nextTick(() => {
        if (sel === 1 || sel === 4) {
          son.toggleSel(mapArr(
            A.sel1.concat(A.sel2, A.sel3, A.sel4),
            v => (v = v.userId) && tableData.find(v2 => v2.userId === v)
          ));
        } else {
          son.toggleSel(mapArr(
            A.sel1.concat(A['sel' + sel], A.sel4),
            v => (v = v.userId) && tableData.find(v2 => v2.userId === v)
          ));
        }
        ;
        sel === 1 && (this.tempZongJian = this.addTable.selectRow || []);
        // console.error(this.addTable.selectRow);
      });
      /* son.toggleSel.sleep(
          0,
          mapArr(
              A,
              v=>( v = v.userId ) && tableData.find( v2=>v2.userId===v )
          )
      ); */
    },

    sel_AddTable() {
      // console.error(this.initEdit,arguments[0]);
      if (this.innerSel2) return this.innerSel2 = false;
      if (this.initEdit) {
        if (this.timer === undefined) {
          this.timer = setTimeout(() => {
            this.initEdit = false;
            const D = this.theAdd;
            Loop(i => D['sel' + i] = [], 1, 4, 1);
            this.theEdit.projectUserInfoList.forEach(v => D['sel' + v.positionType].push(v.with('_selected', true)));
            this.timer = undefined;
            // console.error(111111,D.sel2);
          }, 200);
        }
        ;
        return;
      }
      ;
      // console.error(this.static);
      const theAdd = this.theAdd, sel = theAdd.radio * 1;
      // console.error(this.tempZongJian,arguments[0]);
      if (sel === 1 && theAdd.sel1.length > 0 && this.tempZongJian.length < arguments[0].length) { //总监
        this.innerSel2 = true;
        this.addTable.$refs.myInnerTable.toggleRowSelection(Last(arguments[0]), false);
        return $.msgWarning('每个项目的总监只能选择一个！');
      }
      ;
      const C = myCase[sel];
      (() => {
        const sons = this.addTable.tableData;
        const Sel = mapArr(theAdd["sel" + sel], v => {
          const id = v.userId;
          const find = forEach(sons, v2 => {
            if (v2.userId !== id) return;
            return v2._selected === false ? 1 : v2;
          });
          // find && console.error(find,v.userName,v._selected);
          return find === 1 ? false : find || v;
        });
        // console.error(Sel);
        const Arg = theAdd["sel" + sel] = Sel.concat(mapArr(arguments[0], v => {
          var index;
          if (v._selectable === false) return;
          if (Sel.find(v2 => v2.userId === v.userId)) return;
          v._selected = true;
          return v;
        }));
      }).sleep(50);
      // console.log(C);
      // console.error(arguments[0]);
      /*
      if( sel === 1 || sel === 4 ) { //总监和监理员的时候将其他替换掉
          const A = theAdd["sel"+sel] = Arg;
          Loop(i=>{
              if( i === sel ) return;
              i = "sel" + i;
              theAdd[i] = mapArr( theAdd[i], v=>( i = v.userId ) && !A.find(v2=>v2.userId===i) && v );
          },1,4,1);
      }else { //总代和监理工程师的时候 可以互相兼职
          const A = theAdd["sel"+sel] = Arg;
          [1,4].forEach(i=>{ //替换掉 总监和监理员
              i = "sel" + i;
              theAdd[i] = mapArr( theAdd[i], v=>( i = v.userId ) && !A.find(v2=>v2.userId===i) && v );
          });
      };*/
      // console.error(theAdd.sel2)
    },

    //=====================新增===============================
    /*供应商选择*/
    supplier: async function () {
      var res = await $.post('getAllSupplier', {
        pageNum: 1, //当前页
        pageSize: 10,//每页显示条数
        searchText: this.searchText || ''//搜索文本
      });
      if (!res.success) return;
      this.optionsAll = res.items.map(v => {
        v.label = v.supplierName;
        v.value = v.supplierId + '';
        return v;
      });
      const S = this.theEdit.editSS;
      S && this.$nextTick(() => {
        this.editSS = S;
      });
    },
    showChief(positionType) {
      this.lastPositionType = positionType;
      if (this.istableData2 === false) return this.istableData2 = true; //第一次显示
      // console.log( this.istableData2 );
      // this.addTable.clearSelection();
      this.getShowUser(); //已经在显示， 刷新数据即可
    },
    //获取用户列表
    getShowUser: async function (pageNum, pageSize) {
      var res = await $.post('getUserProject', {
        pageNum: 1,
        pageSize: 10,
        projectId: '',
        positionType: this.lastPositionType,
        searchText: this.searchForm2.searchText2,
      });
      $return('__', res);
    },
    //隐藏的表的查询
    doSearch2() {
      this.getShowUser();
      this.showBack2 = this.searchForm2.searchText2 !== '';
    },
    //隐藏表的人员添加
    doSure2() {
      this.istableData2 = false;
    },
    //新增确定方法
    // doAdd: async function() {
    //   const theAdd = this.theAdd;
    //   var res = await $.post('addProject',{
    //     projectName: theAdd.projectName, //项目名
    //     area: theAdd.area, //片区
    //     major: theAdd.major,//专业
    //     projectState: 0, //状态
    //     startTime: theAdd.theDate[0], //开始日期
    //     endTime: theAdd.theDate[1], //结束日期
    //     projectNumber: theAdd.projectNumber,
    //     programmeName: theAdd.programmeName,
    //     supplierIdList: theAdd.supplierId.map(v=>({supplierId:v})),
    //     userIdList: joinUser(theAdd),//集合
    //   });
    //   // console.log(res);
    //    this.isAdd = false;
    //    this.getAllList();
    //    function joinUser(theAdd) {
    //     var res = [];
    //     Loop(i=>{
    //         res = res.concat( theAdd[ 'sel'+i].map(v=>({userId: v.userId,positionType: i})) );
    //     },1,4,1);
    //     return res;
    //    };
    // },
    // toAdd() {
    //   //调起新增弹窗
    //   this.isAdd = true;
    // },
    //========================================================
    //详情
    handleDetail(index, row) {
      var data = row.projectUserInfoList || [];
      var str = '';
      var str2 = '';
      var str3 = '';
      var str4 = '';
      for (var i = 0; i < data.length; i++) {
        this.alldata = data[i];
        if (data[i].positionType === '1') {
          this.user_name = (data[i].userName || "");
        } else if (data[i].positionType === '2') {
          this.agency = (data[i].positionName || "") + ' -- ';
          str2 += '、' + (data[i].userName || "");
          this.symbol = '；';
        } else if (data[i].positionType === '3') {
          this.engineer = (data[i].positionName || "") + ' -- ';
          str3 += '、' + (data[i].userName || "");
          this.symbol3 = '；';
        } else if (data[i].positionType === '4') {
          this.supervisor = (data[i].positionName || "") + ' -- ';
          str4 += '、' + (data[i].userName || "");
          this.symbol4 = '；';
        }
      }
      ;
      this.$router.push({
        name: "projectRecord",
        params: {
          user_name: this.user_name,
          project_name_record: row.projectName,
          project_number: row.projectNumber,
          project_id: row.projectId,
          user_all2: str2.slice(1),//总代
          user_all3: str3.slice(1),//监理工程师
          user_all4: str4.slice(1),//监理员
          agency: this.agency,
          engineer: this.engineer,
          supervisor: this.supervisor,
          symbol: this.symbol,
          symbol3: this.symbol3,
          symbol4: this.symbol4,
        }
      });
    },
    handleMultiDelete() {
      //调起删除弹窗
      this.isDelete = true;
    },
    handleDelete(index, row) {
      //调起删除弹窗
      this.isDelete = true;
      this.theRow = row;
    },
    doDelete: async function () {
      var res = await $.post('deleteProject', {
        projectId: this.theRow.projectId,
      });
      if (!res.success) return $.msgError(res.msg || 'error!');
      $.msgSuccess(res.msg || 'success!');
      this.isDelete = false;
      this.getAllList();
    },

    inputCode(value) {
      if (this.reg2.test(value)) {
        this.theEdit.projectNumber2 = value;
        // console.error(value);
      }
    },
    handleEdit(index, row) {
      // this.HzgetYezhu()
      this.$forceUpdate()
      this.HzgetYezhu2(row.projectId)


      //调起编辑弹窗
      // row.editDate = [row.startTime||'',row.endTime||''];
      // row.projectNumber2 = this.reg.test( row.projectNumber ) ? row.projectNumber : 'APES-EVA-TJ-PJ'+G.randomStr(3);
      row.projectNumber2 = this.reg.test(row.projectNumber) ? row.projectNumber : 'YPES';
      this.initEdit = true;
      // if ( !this.initEdit && this.initEdit !== row.projectId ) {
      // this.initEdit = row.projectId;
      const D = this.theAdd;
      Loop(i => D['sel' + i] = [], 1, 4, 1);
      console.log("_______", row.projectUserInfoList)
      row.projectUserInfoList.forEach(
        v => D['sel' + v.positionType].push(v.with('_selected', true)));
      // console.error(D.sel2,row.projectUserInfoList);
      // };
      const A = [];
      row.editSS = row.projectSupplierInfoList.map(v => {
        A.push(v.supplierId);
        return v.supplierId + '';
      });
      this.editSS = A;
      this.theEdit = row;
      // this.theEdit.numberType='1'
      this.MCode = Void(row.projectNumber, 'split', ['-']) || initCode.slice(0); //.concat(G.randomStr(3));
      this.Supplier = Void(row.supplier, 'split', ['、']) || [''];

      console.log("this.theEdit",this.theEdit)
      let list=this.theEdit.numberCode.split("-")

      this.theEdit.one=list[0]
      this.theEdit.two=list[1]
      this.theEdit.three=list[2]
      this.theEdit.four=list[3]
      this.theEdit.five=list[4]
      this.theEdit.six=list[5]

      this.setMylist()
      console.log(list)
      this.isEdit = true;

      this.istableData2
        ? this.getShowUser()
        : setTimeout(() => this.initEdit = false, 200);
    },

    docancel() {

      this.isEdit = false;
      this.HzXlList = [{name: "监理公司", code: "YPES", active: false}, {name: "项目", code: "XM", active: false},
        {name: "主项号", code: "ZXH", active: false}, {name: "专业", code: "ZY", active: false},
        {name: "文件类型代码", code: "WJLXDM", active: false}, {name: "序列号", code: "XLH", active: false},
        {name: "无", code: "WU", active: false}]
      this.theEdit.HzuserYzIds=[]
      this.theEdit.userYzIds=[]
      this.$forceUpdate()
    },

    doEdit: async function () {

      if (this.theEdit.numberType == null || this.theEdit.numberType == '') {
        return $.msgError("编号类型必选");
      }

      if (this.theEdit.numberType == 2) {
        if (this.theEdit.one == null || this.theEdit.one == '') {
          return $.msgError("编号规则必选");
        }
        if (this.theEdit.two == null || this.theEdit.two == '') {
          return $.msgError("编号规则必选");
        }
        if (this.theEdit.three == null || this.theEdit.three == '') {
          return $.msgError("编号规则必选");
        }
        if (this.theEdit.four == null || this.theEdit.four == '') {
          return $.msgError("编号规则必选");
        }
        if (this.theEdit.five == null || this.theEdit.five == '') {
          return $.msgError("编号规则必选");
        }
        if (this.theEdit.six == null || this.theEdit.six == '') {
          return $.msgError("编号规则必选");
        }
      }

      this.theEdit.numberCode = this.theEdit.one + '-'  + this.theEdit.two + '-' + this.theEdit.three + '-' + this.theEdit.four + '-' + this.theEdit.five + '-' + this.theEdit.six
      if (this.theEdit.numberType ==1) {
        this.theEdit.numberCode=null
      }

      if(this.theEdit.HzuserYzIds==null||this.theEdit.HzuserYzIds.length==0 ){
        return $.msgError("业主必选");
      }
      let map={
        userId:"",
        positionType:100
      }
      let list=[]
      console.log( this.theEdit.HzuserYzIds)
      this.theEdit.HzuserYzIds.map((v,i)=>{
        map={
          userId:"",
          positionType:100
        }

          map.userId=v
          list.push(map)
      })
      console.log("---1---2---3")
      console.log(list)
      this.theEdit.userYzIds=JSON.stringify(list)

      const test = /^[A-Za-z0-9]+$/i;
      if (!test.test(this.MCode[1] || 'a') || !test.test(this.MCode[2] || 'a') || !test.test(this.MCode[3] || 'a')) {
        return $.msgError("编号只能输入字母或数字！");
      }
      ;
      const theAdd = this.theAdd;

      var res = await $.post('updateProjectSupplierAndPosition', {
        projectState: this.theEdit.projectState,
        // projectNumber: this.MCode.join('-'),
        projectNumber: this.theEdit.projectNumber,
        projectId: this.theEdit.projectId,
        // supplierIdList: this.editSS.map(v=>({supplierId:v})),
        // supplier:this.theEdit.supplier,
        supplier: this.Supplier.join('、'),
        userIdList: joinUser(theAdd) || JSON.string([]),//集合
        numberCode: this.theEdit.numberCode,
        numberType: this.theEdit.numberType,
        userYzIds: this.theEdit.userYzIds
      });
      // var res2 = await $.post('updateProjectNumber',{
      //   projectNumber:this.MCode.join('-'),
      //   projectId:this.theEdit.projectId,
      // });
      this.isEdit = false;
      this.HzXlList = [{name: "监理公司", code: "YPES", active: false}, {name: "项目", code: "XM", active: false},
        {name: "主项号", code: "ZXH", active: false}, {name: "专业", code: "ZY", active: false},
        {name: "文件类型代码", code: "WJLXDM", active: false}, {name: "序列号", code: "XLH", active: false},
        {name: "无", code: "WU", active: false}]
      this.getAllList();

      function joinUser(theEdit) {
        var res = [];
        Loop(i => {
          res = res.concat(theEdit['sel' + i].map(v => ({userId: v.userId, positionType: i})));
        }, 1, 4, 1);
        return res;
      };
      this.theEdit.HzuserYzIds=[]
      this.theEdit.userYzIds=[]
      this.$forceUpdate()
    },




    doSearch() {
      //搜索方法
      this.getAllList();
      this.showBack = true;
    },

    goBack() {
      this.$router.go(-1);
    },
    openLoading() {
      //loading请求等待
      this.loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
    },
    getAllList: async function (pageNum, pageSize) {
      var res = await $.post('getAllProject', {
        projectLeaderId: localStorage.getItem("userId"),
        pageNum, //当前页
        pageSize,//每页显示条数
        searchText: this.searchForm.searchText//搜索文本
      });
      res.success && res.items.forEach(v => v.projectNumber2 = v.projectNumber)
      $return('__', res);
      // res = res.items || [];
      // for(var i = 0; i < res.length; i++){
      //   this.allitems = res[i];
      //   this.supplierItems =  this.allitems;
      //   var resItem = this.supplierItems
      //   //console.log(this.allitems);
      //   var allSupplier = resItem.projectSupplierInfoList || [];
      //   var str = '';
      //   for(var j = 0; j < allSupplier.length; j++){
      //     this.alldata = allSupplier[j];
      //     this.supp = this.alldata.supplierName;
      //     str += '、' + this.supp;//拼接多个供应商
      //     this.supplierName = str.slice(1);
      //   }
      // };
    },
  },

  // mounted() {this.restaurants = this.loadAll();}
};
</script>
<style scoped>
.assignment_parent {
  width: 193px;
  padding: 12px;
  background: #E1E1E1
}

.child_div {
  text-align: center;
  padding: 0 10px;
  background: #FAFAFA;
  margin-bottom: 8px;
}

.child_div_last {
  text-align: center;
  padding: 0 10px;
  background: #FAFAFA;
}

.child_div span,
.child_divTwo span {
  color: #000;
}

.child_div_last span,
.child_div_lastTwo span {
  color: #000;
}

/*显示隐藏表格*/
.showTable {
  border: 1px solid #d4d4d4;
  margin-top: 10px;
  width: 73%;
  margin-left: 110px;
}

.table_row {
  border-bottom: 1px solid #d4d4d4;
  padding-left: 10px;
}

/*修改 二级隐藏表格*/
.showTableTwo {
  border: 1px solid #d4d4d4;
}

.child_divTwo {
  text-align: center;
  padding: 6px 10px;
  background: #FAFAFA;
  margin-bottom: 8px;
}

.child_div_lastTwo {
  text-align: center;
  padding: 6px 10px;
  background: #FAFAFA;
}

/*新增 供应商选择 分页*/
.page_div {
  border-top: 1px solid #d4d4d4;
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
  padding: 10px 10px 0 10px;
}

.page_i {
  /*background:#7BB6D5;*/
  background: #367FA8;
  height: 24px;
  padding: 0 5px;
  cursor: pointer;
  border-radius: 50%;
}

.page_i:hover {
  opacity: 0.8
}

.page_i_color {
  line-height: 24px;
  color: #fff
}

/*供应商 图标 设置*/
.Icon_margin {
  margin-left: 8px;
  cursor: pointer;
  font-size: 24px !important;
}

.icon_blue {
  color: #428bca;
}

.icon_red {
  color: red;
}
</style>


